package enumandlambda;

import java.util.Random;
import java.util.concurrent.*;

/**
 * @author shkstart
 * 有返回值的线程池
 * @create 2022-12-07-20:03
 */
public class ThreadPoolDemo2 {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        ExecutorService threadPool = Executors.newFixedThreadPool(5);

        Future<Integer> result = threadPool.submit(new Callable<Integer>() {
            @Override
            public Integer call() throws Exception {
                int num = new Random().nextInt(10);
                System.out.println("升成随机数"+num);
                return num;
            }
        });
        System.out.println("得到线程池返回结果"+result.get());

    }
}
